﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using DevExpress.Web.ASPxHeadline;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxGridView;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;

public partial class CARByCompany : ICPRelationshipPage
{
    public DateTime m_dtmStartDate;
    public DateTime m_dtmEndDate;
    public DataTable m_dtCAR;


    #region Properties
    
    
    #endregion Properties

    #region Event Handlers

    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);

        Page.Title = "ICP Lintasarta: Relationship, Change CAR By Company";
        if (!IsPostBack && !IsCallback)
        {
        }
    }
    protected void cbkCA_Callback(object sender, CallbackEventArgs e)
    {
        System.Threading.Thread.Sleep(KGlobal.AJAX_WAIT_TIME);
        if (e.Parameter.ToUpper().StartsWith("SELECT"))
        {
            e.Result = HandleSelect(e.Parameter);
        }
        else if (e.Parameter.ToUpper().StartsWith("CHANGE"))
        {
            e.Result = HandleChange(e.Parameter);
        }
    }
    #endregion Event Handlers

    #region Custom Methods
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    protected String HandleSelect(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        String sxReturn = String.Empty;
        Cached.ICPCARTable ccICPCAR = new Cached.ICPCARTable();
        DataTable dtICPCAR;
        int iCompanyId = int.Parse(sxSplitted[1]);
        dtICPCAR = ccICPCAR.GetCARListByCompany(iCompanyId,true);
        String sxCAR = String.Empty;
        if (dtICPCAR.Rows.Count > 0)
        {
            sxCAR = dtICPCAR.Rows[0]["EMPLOYEE_NAME"].ToString();
        }
        return sxCAR;
    }
    protected String HandleChange(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        String sxReturn = String.Empty;
        int iCompanyId = Convert.ToInt32(sxSplitted[1]);
        String sxCarId = sxSplitted[2];
        DBQuery.CARSpocTable.ChangeCARByCompany(iCompanyId, sxCarId);
        sxReturn = "CHANGE";
        return sxReturn;
    }
    #endregion Custom Methods
}
